//
//  UIBarBtnItem+Extension.swift
//  DouYuZB
//
//  Created by DSDL on 2016/10/25.
//  Copyright © 2016年 鼎商动力. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    //    class func creatItem(imageName : String, highImageName : String, size : CGSize) -> UIBarButtonItem {
    //
    //        let btn = UIButton()
    //        btn.setImage(UIImage(named:imageName ), forState: .Normal)
    //        btn.setImage(UIImage(named: highImageName), forState: .Highlighted)
    //
    //        btn.frame = CGRect(origin: CGPointZero, size: size)
    //
    //        return UIBarButtonItem(customView: btn)
    //    }
    //
    
    //便利构造函数
    convenience init(imageName : String, highImageName : String = "", size : CGSize = CGSize.zero) {
        //1.创建btn
        let btn = UIButton()
        btn.setImage(UIImage(named:imageName ), for: UIControlState())
        //2/设置btn 属性
        if highImageName != "" {
            btn.setImage(UIImage(named: highImageName), for: .highlighted)
        }
        
        //3.设置btn的尺寸
        if size == CGSize.zero {
            btn.sizeToFit()
        }else{
            btn.frame = CGRect(origin: CGPoint.zero, size: size)
        }
        //4. 创建UIBarButtonItem
        self.init(customView : btn)
    }
}
